package SqlHelper;

import java.sql.ResultSet;

public class SqlSentence {

	public static String insertSql(String tableName){
		String insertSql="insert into "+tableName+" values(";
		int colNum = OperateDataBase.returnColNum(tableName);
		for(int i=0;i<colNum;i++){
			if(i==colNum-1){
				insertSql+="?";
				break;
			}
			insertSql+="?,";
		}
		insertSql+=")";
		return insertSql;
	}
	public static String deleteSql(String tableName,String para[]){
		String title_1 = para[0];
		String value_1 = para[1];
		String title_2 = para[2];
		String value_2 = para[3];
		String deleteSql = "delete from "+tableName+" where "+title_1+" = "+value_1+" and "+title_2+" = "+value_2;
		return deleteSql;
	}
    public static String updateSql(String tableName,String para[]){
    	String updateSql = null;
    	if(para.length==6){
    		String title_uptate = para[0];
    		String value_update = para[1];
    		String title_1 = para[2];
    		String value_1 = para[3];
    		String title_2 = para[4];
    		String value_2 = para[5];
    	    updateSql = "update "+tableName+" set "+title_uptate+" = "+"'"+value_update+"'"+" where "+title_1+" = "+"'"+value_1+"'"+" and "+title_2+" = "+"'"+value_2+"'";
    	}else if(para.length==4){
    		String title_uptate = para[0];
    		String value_update = para[1];
    		String title_1 = para[2];
    		String value_1 = para[3];
    	    updateSql = "update "+tableName+" set "+title_uptate+" = "+"'"+value_update+"'"+" where "+title_1+" = "+"'"+value_1+"'"+" ";
    	}
    	
		
    	return updateSql;
    }
	public static String findSql(String tableName,String para[]){		
		String sql = null;
		if(para.length==3){
			String title_get= para[0];
			String title_1= para[1];
			String value_1= para[2];
			sql = "select "+title_get+" from "+tableName+" where "+title_1+" = "+"'"+value_1+"'"+" ";
		}else if(para.length==5){
			String title_get= para[0];
			String title_1= para[1];
			String value_1= para[2];
			String title_2= para[3];
			String value_2= para[4];
			sql = "select "+title_get+" from "+tableName+" where "+title_1+" = "+value_1+" and "+title_2+" = "+value_2+"";
		}else if(para.length==2){
			String title_find= para[0];
			String value_find= para[1];
			sql = "select "+title_find+" from "+tableName+" where "+title_find+" = "+"'"+value_find+"'"+"";
		}
		return sql;
	}
   	public static String findLineSql(String tableName,String para[]){
		String sql = null;
		if (para.length==2) {
			String title_search = para[0];
			String value_search = para[1];
			sql = "select * from " + tableName + " where " + title_search
					+ " = " + "'" + value_search + "'" + " ";
		} else if(para.length==4){
			String title_search_1 = para[0];
			String value_search_1 = para[1];
			String title_search_2 = para[2];
			String value_search_2 = para[3];
			sql = "select * from " + tableName + " where " + title_search_1
					+ " = " + "'" + value_search_1 + "'" + " and "+title_search_2
					+ " = " + "'" + value_search_2 + "'"+"";

		}
        return sql;
	}
    

}
